var imgLoaded = true;
var count = 0;
$(function () {
    var b = 1;
    var a = 1;
    var c = 'http://api.zhej360.com/index/getNotices?page=' + b + '&page_size=' + a;
    loadArts(c, b);
    $(window).scroll(function () {
        if (($(window).height() + document.body.scrollTop) + 10 >= document.body.scrollHeight) {
            if (imgLoaded) {
                b += a;
                c = 'http://api.zhej360.com/index/getNotices?page=' + b + '&page_size=' + a;
                imgLoaded = false;
                $(".load-more").show();
                loadArts(c, b)
            }
        }
    })
});
function appendLi(c) {
    var c = JSON.parse(c);

    // 首次加载数据没空时显示"没有公告"
    if (count < 1 && c.data.length == 0) {
        $(".load-more").hide();
        $(".artfin_no_style").show();

        // 提示关闭之前，不让加载数据
        imgLoaded = false;
        setTimeout(function() {
            $(".artfin_no_style").hide();
            imgLoaded = true;
        }, 3000);
    } 

    // 数据加载完毕提示
    else if(count >=1 && c.data.length == 0) {
        $(".load-more").html('无数据更新了');

        // 提示关闭之前，不让加载数据
        imgLoaded = false;
        setTimeout(function() {
            $(".load-more").hide();
            imgLoaded = true;
        }, 3000);
    } 

    // 数据加载
    else {
        $(".load-more").hide();
        for (var i = 0; i < c.data.length; i++) {
            var d = c.data[i];
            var b = '<li><a href="' + d.url + '">' + d.title + "<time>" + d.ctime + "</time></a></li>";
            $(".notice_big_style ul").append(b)
        }
        imgLoaded = true;
    }
    count++;
};

/**
 * 公告轮播
 */
$(function() {
    $.ajax({
        dataType: 'json',
        type: 'post',
        url: 'http://api.zhej360.com/index/getBanners',
        success: function(resp) {
            if(resp.data.length != 0) {

                // 加载轮播数据
                $.each(resp.data, function(i, item) {
                    var content = '<div class="swiper-slide"><a href="'+ item.slide_url + '"><img src="' + item.slid_pic + '" width="100%" height="200" alt="焦点图"/></a></div>';
                    $('.swiper-wrapper').append(content);
                });

                // 轮播js渲染
                var mySwiper = new Swiper('.swiper-container', {
                    direction: 'horizontal',
                    loop: true,
                    autoplay: 3000,
                    height: 200,
                    pagination: '.swiper-pagination'
                });
            } else{
                alert('没有焦点图');
            }
        }
    });
});
